<?php 

require "../gobal.php";

function doSubmit(){



	$issue_ids=$_POST["PlanIdList"];
    $device_id=$_POST["VersionId"];
    $device_color=$_POST["DeviceColor"];
    $order_type=$_POST["OrderType"];
    $service_method=$_POST["ServiceType"]=="1"?"visit":"express";
    $visit_contact_id=$_POST["UserAddressId"];
    $visit_arrive_at=$_POST["ComeTime"];
	$PayCheckoutType=$_POST["PayCheckoutType"];
    $PayCheckoutInfo=$_POST["PayCheckoutInfo"];
    $express_code=$_POST["PostId"];
    $PostInfo=$_POST["PostInfo"];
	$express_sender_name=$_POST["PostName"];
	$express_sender_address=$_POST["PostAddress"];
    $express_sender_tel=$_POST["PostCallPhone"];
	$remark=$_POST["remark"];

	//$remark = iconv("utf-8","gbk",$remark);

	$ordercode="xxxx";

	$total_price=$_POST["total_price"];
	//$visit_address_id=0;
	
	$customer=currCustomer();
     $customer_id=$customer["id"];

	$sql="INTO `order_sum`(`remark`, `code`, `created_at`, `customer_id`, `device_id`, `device_color`, `total_price`,  `service_method`, `express_code`, `express_sender_name`, `express_sender_address`, `express_sender_tel`, `visit_contact_id`, `visit_arrive_at`,order_type) VALUES ";

	$sql=$sql."('$remark',UNIX_TIMESTAMP(),NOW(),$customer_id,$device_id,'$device_color',$total_price,'$service_method','$express_code','$express_sender_name','$express_sender_address','$express_sender_tel',$visit_contact_id, '$visit_arrive_at','$order_type')";

	$orderId=insert_row($sql);

    switch($order_type){

		case "phonefix": 
		$sql="INTO `order_item`( `order_id`, `issue_id`, `issue_price`, `issue_name`) select $orderId,di.id,di.repair_amount,di.name from device_issue di WHERE di.id in ($issue_ids)";
        insert_row($sql);
		
		break;
		case "padfix": $val="平板維修";break;
		case "recovery": $val="手機回收";break;
		case "memoryup": 
		    
		break;
        default : break;
	}
    
	$msg="";
	$success='false';
	

	if($orderId>0){
       $success='true';
	}



    echo "{ success:$success,orderId:$orderId,msg:'$msg',remark:'$remark'}";
	//echo "{orderId:$orderId,msg:'$msg',success:$success}";
    
}


function doUpdateRateScore(){
    
    $oid=$_POST["oid"];
    $score=$_POST["score"];
    
    $sql="order_sum set rate_score=$score,rate_at=NOW() where id=$oid";
    
    $eff=update_row($sql);
    
    echo "{eff:$eff}";
    
}



header("Content-type: application/json; charset=utf-8"); 

$action=$_GET["action"] ;



switch($action){

	case "doSubmit": doSubmit();break;
    case "doUpdateRateScore": doUpdateRateScore();break;
	default : break;

}



?>